import { Metadata } from 'next'
import { getBiddingsForReceive } from '@/lib/bidding/service'
import { GetBiddingsSchema, searchParamsCache } from '@/lib/bidding/validation'
import { BiddingsReceiveTable } from '@/lib/bidding/receive/biddings-receive-table'
import { useTranslation } from "@/i18n"

export const metadata: Metadata = {
  title: '입찰서 접수 및 마감',
  description: '입찰서 접수 및 마감 현황을 확인하고 개찰을 진행할 수 있습니다.',
}

interface BiddingReceivePageProps {
  params: Promise<{lng: string}>
  searchParams: Promise<Record<string, string | string[] | undefined>>
}

export default async function BiddingReceivePage({
  params,
  searchParams,
}: BiddingReceivePageProps) {
  // URL 파라미터 검증
  const searchParamsResolved = await searchParams
  const search = searchParamsCache.parse(searchParamsResolved)
  const {lng} = await params
  const {t} = await useTranslation(lng, 'menu')

  // 데이터 조회
  const biddingsPromise = getBiddingsForReceive(search)

  return (
    <div className="flex flex-col gap-4 p-4">
      <div className="flex items-center justify-between">
        <div>
          <h1 className="text-2xl font-bold tracking-tight">{t('menu.procurement.bid_receive')}</h1>
          <p className="text-muted-foreground">
            {t('menu.procurement.bid_receive_desc')}
          </p>
        </div>
      </div>

      <BiddingsReceiveTable promises={Promise.all([biddingsPromise])} />
    </div>
  )
}